import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionTraversal {
    public static void main(String[] args) {
        //三种遍历方式

        //1、迭代器遍历
        Collection<String> coll1 =new ArrayList<>();
        coll1.add("aaa");
        coll1.add("bbb");
        coll1.add("ccc");
        coll1.add("ddd");

        Iterator<String> it= coll1.iterator();
        while (it.hasNext()){
            String str=it.next();
            System.out.println(str);
        }


        System.out.println("-----------------------------");


        //2、增强for循环
        Collection<String> coll2 =new ArrayList<>();
        coll2.add("zhangsan");
        coll2.add("lisi");
        coll2.add("wangwu");

        for (String s: coll2){
            s="qqq";//没有改变内容
        }

        System.out.println(coll2);//zhangsan lisi wangwu


        System.out.println("-----------------------------");


        //3、lambda表达式
        coll2.forEach(s-> System.out.println(s));
    }
}
